<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>阶乘递归函数</title>
</head>
<body>
<script>
    function x(n){
        if(n === 1){
            return 1;
        }else {
            return n * x(n-1);
            //n=5
            //5 * x(5-1)=5 * x(4)  5*24=120 最终输出5的阶乘为120
            // x(4)=4 * x(4-1)=4 * x(3) 4*6=24
            // x(3)3 * x(3-1)=3 * x(2) 3*2=6
            // x(2)=2 8 x(2-1)=2 * x(1) 2*1=2
        }
    }
    console.log(x(5));
</script>
</body>
</html>